# import os
from flask import Flask, render_template,jsonify
from middleware import init_middleware
from model import init_db
from route import init_routes
from tools.validate import ValidationError

app = Flask(__name__, static_folder="static")
app.config['UPLOAD_FOLDER'] = 'uploads/avatars'
# secret_key = os.getenv('SECRET_KEY')
app.config["SECRET_KEY"] = 'secret_key'
init_middleware(app)
init_routes(app)
init_db(app)

@app.route("/")
def index():
    return jsonify({"message": "hello"})

@app.route("/your_endpoint")
def your_endpoint():
    return jsonify({"message": "hello"})

@app.errorhandler(ValidationError)
def handle_validation_error(e):
    return jsonify({
        'status': 'failed',
        'message': e.message,
        'data': None
    }), e.status_code


if __name__ == '__main__':
    app.run(port=5000,debug=True)
